package test.ui {
	import gear.ui.model.ListModel;
	import gear.ui.model.PageModel;
	import gear.ui.model.SyncPageData;

	import flash.events.Event;
	import flash.utils.clearTimeout;
	import flash.utils.getTimer;
	import flash.utils.setTimeout;

	/**
	 * @author admin
	 */
	public class TestSyncPageData extends SyncPageData {
		private var _pageModel : PageModel;
		private var _timeout : uint;

		private function call_getPage() : void {
			clearTimeout(_timeout);
			_isLoaded = false;
			_timestamp = getTimer();
			_list = _pageModel.getList(_page);
			dispatchEvent(new Event(Event.COMPLETE));
		}

		public function TestSyncPageData(page : int, pageSize : int) {
			super(page, pageSize);
			var listModel : ListModel = new ListModel();
			listModel.source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
			if (_page == 1) {
				_total = listModel.size;
			}
			_pageModel = new PageModel(pageSize, listModel);
		}

		override public function syncLoad() : void {
			if (_isLoaded) {
				return;
			}
			_isLoaded = true;
			_timeout = setTimeout(call_getPage, 1000);
		}
	}
}
